/*
 * @(#)JdbcConnection.java
 *
 * Copyright 2001 Orlin Tomov. All Rights Reserved.
 * 
 */

package dbu.jdbc;

import java.sql.SQLException;

import dbu.Dbu;
import dbu.DbuException;
import dbu.jdbc.facade.JdbcStatementImpl;
import dbu.sql.SqlCommand;

/**
 * A class ...
 *
 * @version     1.00, 01/09/01
 * @author      Orlin Tomov
 */

public final class JdbcStatement extends JdbcStatementImpl {

	JdbcStatement() throws SQLException {
	}

	/** Executes an SQL statement that returns a single ResultSet object. */
	@Override
	public JdbcResultSet executeQuery(String sql) throws SQLException {
		try {
			SqlCommand sqlCmd = new SqlCommand(sql);
			JdbcResultSet resultSet = Dbu.getResult(sqlCmd);
			return resultSet;
		} catch (DbuException e) {
			throw new SQLException(e.getMessage());
		}
	}

	/** Executes an SQL INSERT, UPDATE or DELETE statement. */
	@Override
	public int executeUpdate(String sql){
		SqlCommand sqlCmd = new SqlCommand(sql);

		int result = 0;
		if(sqlCmd.getCmd().equals(SqlCommand.DELETE)){
			result = Dbu.delete(sqlCmd);
		}
		if(sqlCmd.getCmd().equals(SqlCommand.UPDATE)){
			result = Dbu.update(sqlCmd);
		}
		if(sqlCmd.getCmd().equals(SqlCommand.INSERT)){
			result = Dbu.insert(sqlCmd);
		}
		return result;
	}

}
